<?php


// Inialize session
session_start();

// Check, if username session is NOT set then this page will jump to login page
if (!isset($_SESSION['username'])) {
        header('Location: index.php');
}


?>
<!-- BY BING HUA -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<meta http-equiv="content-type" content="text/html; charset=utf-8" />
	<title>
		User Accounts
	</title>
	<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
	<meta name="keywords" content="" />
	<meta name="description" content="" />
	<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
	<style type="text/css">

	</style> 
	
	<?php
		include 'functions.php';
	?>
</head>

<body>
		<?php
			include 'headinfo.php';
		?>
	<hr />
	<div id="header">
		<?php
			$thispage = "Administrative";
			require 'menu.php';
		?>
		<!-- end #menu -->
	</div>
	<!-- end #header -->
	<!-- end #header-wrapper -->
	<div id="page">
		<div id="content">
		  	<div class="post">
		  		
			  	<h2 class="title"><a href="#">Administrative</a></h2>
							
				<p class="meta"></p>
				<?php
					$thissubpage ="User Settings";
					require 'menu_admin.php';
				?>
				
				
				<?php

    				if(isset($_POST['submitAdd'])){
    					if(empty($_POST['username'])||empty($_POST['password'])||empty($_POST['repassword'])){
							 echo "<script type=\"text/javascript\">window.alert(\"please set username and password\")</script>"; 
    						
    					}
						elseif ($_POST['password'] != $_POST['repassword'])
						{	echo "<script type=\"text/javascript\">window.alert(\"passwords not match\")</script>"; 
						}
						else{
    						$username = $_POST['username'];
    						$password = $_POST['password'];
    						addUser($username, $password, NULL, NULL, NULL);
    						
    					} 				
    				}
    				
					if(isset($_POST['submitDelete'])){
    					if($_POST['AllUsers']=="Select"){
    						print('please set a user to delete.');	
    					}else{
    						$username = $_POST['AllUsers'];
    						deleteUser($username);
    						
    						
    					}
    					
    				}
    	
    			?>
				<table class="tablecss">
				<tr>
				<td>
				<h2>Add Account</h2>
				<form name="form" method="post" action="UserAccounts.php">
       	 		<p>
					Username: <input maxlength="50" name="username" type="text" />&nbsp;&nbsp; 
					<br><br>
					Password: <input maxlength="50" name="password" type="password" />
					<br><br>
					Type Password Again: <input maxlength="50" name="repassword" type="password" />
					&nbsp;&nbsp;&nbsp;&nbsp;
		 			<input name="submitAdd" type="submit" value="Add" />
		 		</p>
		 		</form>
		 		</td>
		 		</tr>
		 		
		 		<tr>
				<td>
		 		<h2>Delete Account</h2>
		 		<form name="form" method="post" action="UserAccounts.php">
				<p>Delete User:
					<select name="AllUsers">
					<option value="Select">Select User</option>
					<?php 
					
            			$allUsers = getAllUsers();
            			for($i = 0; $i<count($allUsers); $i++){
            				echo "<option value=\"".$allUsers[$i]['username']."\">".$allUsers[$i]['username']."</option>";
            			}
            		
           			?>
					</select>
					&nbsp; 
					<input name="submitDelete" type="submit" value="Delete" />
				</p>
          		</form>
				</td>
		 		</tr>
		 		</table>
			
			</div>
		</div>
	</div>
	<div style="clear: both;">&nbsp;</div>
	<div id="footer">
	<p>Copyright (c) 2010 Dilmun Hill Team.</p>
</div>
	
</body>

</html>